<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>django webssh 例子</title>


    <link href="https://cdnjs.cloudflare.com/ajax/libs/xterm/3.13.2/xterm.css" rel="stylesheet" type="text/css"/>

</head>
<body>


<div id="terms"></div>
</body>

<script src="https://cdnjs.cloudflare.com/ajax/libs/xterm/3.13.2/xterm.js"></script>


<script>
    var socket = new WebSocket('ws://' + window.location.host + '/ws/{{ name }}/{{ namespace }}');

    socket.onopen = function () {

        var term = new Terminal();
        term.open(document.getElementById('terms'));


        term.on('data', function (data) {
            console.log(data);
            socket.send(data);
        });

        socket.onmessage = function (msg) {
            console.log(msg);
            console.log(msg.data);
            term.write(msg.data);
        };
        socket.onerror = function (e) {
            console.log(e);
        };

        socket.onclose = function (e) {
            console.log(e);
            term.destroy();
        };
    };


</script>


</html>